package top.yueyazhui.ask_for_leave.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import top.yueyazhui.ask_for_leave.dto.AskForLeaveDto;
import top.yueyazhui.ask_for_leave.dto.TaskDto;
import top.yueyazhui.ask_for_leave.entity.User;
import top.yueyazhui.ask_for_leave.model.Response;
import top.yueyazhui.ask_for_leave.service.AskForLeaveService;

import java.io.IOException;
import java.util.List;

/**
 * @Author yueyazhui
 * @Date 2023/2/11
 */
@RestController
public class AskForLeaveController {

    @Autowired
    AskForLeaveService askForLeaveService;

    /**
     * 申请，流程启动
     * @param askForLeaveDto
     * @return
     */
    @PostMapping("apply")
    public Response apply(@RequestBody AskForLeaveDto askForLeaveDto) {
        return askForLeaveService.apply(askForLeaveDto);
    }

    /**
     * 审批用户列表
     * @return
     */
    @GetMapping("approveUserList")
    public List<User> getApproveUserList() {
        return askForLeaveService.getApproveUserList();
    }

    /**
     * 当前用户待审批流程列表
     * @return
     */
    @GetMapping("pendApproveList")
    public List<AskForLeaveDto> getPendApproveList() {
        return askForLeaveService.getPendApproveList();
    }

    /**
     * 实时进度图
     * @param processInstanceId
     * @throws IOException
     */
    @GetMapping("realTimeProgressImage/{processInstanceId}")
    public void getRealTimeProgressImage(@PathVariable String processInstanceId) throws IOException {
        askForLeaveService.getRealTimeProgressImage(processInstanceId);
    }

    /**
     * 当前用户任务列表
     * @return
     */
    @GetMapping("taskList")
    public List<TaskDto> getTaskList() {
        return askForLeaveService.getTaskList();
    }

    /**
     * 审批
     * @param taskDto
     * @return
     */
    @PostMapping("approve")
    public Response approve(@RequestBody TaskDto taskDto) {
        return askForLeaveService.approve(taskDto);
    }

    /**
     * 当前用户历史流程列表
     * @return
     */
    @GetMapping("historyList")
    public List<AskForLeaveDto> getHistoryList() {
        return askForLeaveService.getHistoryList();
    }
}
